package com.ag.zlw.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbPlanGrade;
import com.ag.common.BaseAction;
import com.ag.common.IDUtil;
import com.ag.zlw.service.PlanGradeService;

/**
 * 预案等级
 * 
 * @author 钟龙伟
 * 
 */

@Scope("prototype")
@Controller("PlanGradeAction")
public class PlanGradeAction extends BaseAction {
	private static final long serialVersionUID = -1478025497648926124L;
	@Resource(name = "PlanGradeService")
	private PlanGradeService service;
	private List<TbPlanGrade> planGradeList;
	private String message;
	private String pgId;
	private String pgName;
	private String pgDetail;

	TbPlanGrade tbPlanGrade = new TbPlanGrade();

	public String find() {
		try {
			planGradeList = service.findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "main";
	}

	public String delete() {
		tbPlanGrade.setPgId(pgId);
		try {
			service.delete(tbPlanGrade);
			this.setMessage("delete success!");
		} catch (Exception e) {
			this.setMessage("delete fail!");
		}
		return "delete_success";
	}

	public String add() {
		tbPlanGrade.setPgName(pgName);
		tbPlanGrade.setPgDetail(pgDetail);
		tbPlanGrade.setA(IDUtil.PRESERVE);
		try {
			service.save(tbPlanGrade);
			this.setMessage("save success!");
		} catch (Exception e) {
			this.setMessage("save fail!");
		}
		return "add_success";
	}

	public String modify() {
		tbPlanGrade.setPgId(pgId);
		tbPlanGrade.setPgName(pgName);
		tbPlanGrade.setPgDetail(pgDetail);
		tbPlanGrade.setA(IDUtil.PRESERVE);
		try {
			service.modify(tbPlanGrade);
			this.setMessage("modify success!");
		} catch (Exception e) {
			this.setMessage("modify fail!");
		}
		return "modify_success";
	}

	public void setPlanGradeList(List<TbPlanGrade> planGradeList) {
		this.planGradeList = planGradeList;
	}

	public List<TbPlanGrade> getPlanGradeList() {
		return planGradeList;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getMessage() {
		return message;
	}

	public String getPgId() {
		return pgId;
	}

	public void setPgId(String pgId) {
		this.pgId = pgId;
	}

	public String getPgName() {
		return pgName;
	}

	public void setPgName(String pgName) {
		this.pgName = pgName;
	}

	public String getPgDetail() {
		return pgDetail;
	}

	public void setPgDetail(String pgDetail) {
		this.pgDetail = pgDetail;
	}
}
